﻿var $ = document.getElementById.bind(document);
var dom = require("ace/lib/dom");
//add command to all new editor instaces
require("ace/commands/default_commands").commands.push({
    name: "Toggle Fullscreen",
    bindKey: "F11",
    exec: function (editor) {
        dom.toggleCssClass(document.body, "fullScreen")
        dom.toggleCssClass(editor.container, "fullScreen")
        editor.resize()
    }
});

var editor = ace.edit("editor");
editor.setTheme("ace/theme/chrome");
editor.getSession().setMode("ace/mode/html");
editor.setValue(hfHtml.val());
function beforeSubmit() {
    hfHtml.val(editor.getValue());
    return true;
}
function scroll(speed) {
    var top = editor.container.getBoundingClientRect().top
    speed = speed || 10
    if (top > 60 && speed < 500) {
        if (speed > top - speed - 50)
            speed = top - speed - 50
        else
            setTimeout(scroll, 10, speed + 10)
        window.scrollBy(0, speed)
    }
}
